﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;

namespace OpenAuth.App
{
    /// <summary>
    /// 门诊预交金充值
    /// </summary>
    public class BMZXX003App : ApiBaseApp<BMZXX003>
    {

        public BMZXX003App(IApiRepository<BMZXX003> repository, IRepository<BMZXX003> repo) : base(repository)
        {
        }
        public IEnumerable<BMZXX003Response> PutCardCharge(BMZXX003 model)
        {


            List<SqlParameter> param = new List<SqlParameter>();
            param.Add(new SqlParameter("@Patid", model.patid));
            param.Add(new SqlParameter("@Paytype", model.paytype));
            param.Add(new SqlParameter("@Paymoney", model.paymoney));
            param.Add(new SqlParameter("@Paylsh", model.paylsh));
            param.Add(new SqlParameter("@Paytime", DateTime.Now.ToString("yyyyMMdd")));
            param.Add(new SqlParameter("@Hisjylsh", model.hisjylsh));
            param.Add(new SqlParameter("@Ptlsh", model.ptlsh));
            param.Add(new SqlParameter("@Hisddh", model.hisddh));
            param.Add(new SqlParameter("@Czyh", "hf001"));
            var result = Put("exec usp_web_webtrans_BMZXX003 @patid=@Patid,@paytype=@Paytype,@paymoney=@Paymoney,@paylsh=@Paylsh,@paytime=@Paytime,@hisjylsh=@Hisjylsh,@ptlsh=@Ptlsh,@hisddh=@Hisddh,@czyh=@Czyh", param);
            List<BMZXX003Response> list = new List<BMZXX003Response>();
            //返回成功结果
            if (result != null && result.Rows[0][0].ToString() == "T")
            {
                list.Add(new BMZXX003Response { yjxh = result.Rows[0][1].ToString(), dgye = result.Rows[0][2].ToString(), hisjylsh = result.Rows[0][3].ToString(), hisddh= result.Rows[0][4].ToString(), Code = 200 });
            }
            //返回错误结果
            else
            {
                list.Add(new BMZXX003Response { Code = 400, Message = result.Rows[0][1].ToString() });
            }

            return list.AsEnumerable<BMZXX003Response>();
           
        }
        /// <summary>
        /// 验证充值时平台流水号是否已经存在
        /// </summary>
        /// <param name="ptlsh"></param>
        /// <returns></returns>
        public bool VerifyPtlsh(string ptlsh)
        {
            List<SqlParameter> param = new List<SqlParameter>();
            param.Add(new SqlParameter("@ptlsh", ptlsh));
            var result = Put("select 1 from YY_PAYDETAILK where zflsh=@ptlsh", param);
            if (result!=null&&result.Rows.Count>0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
